package com.nbjtjc.safe.mapper.sys;

import com.nbjtjc.safe.model.sys.SysRole;
import com.nbjtjc.safe.model.sys.SysUserRole;
import com.nbjtjc.util.MyMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SysUserRoleMapper extends MyMapper<SysUserRole> {


    @Select("SELECT sys_role.role from sys_user_role LEFT JOIN sys_role ON sys_role.id=sys_user_role.roleId " +
            "where sys_user_role.userId=#{userId}")
    List<String> findRoleByUserId(@Param("userId") int userId);
    @Select("select * from sys_user_role where userId=#{userId}")
    List<SysUserRole> findUserRoleByUserId(@Param("userId") int userId);

    @Select("SELECT sys_role.* from sys_user_role LEFT JOIN sys_role ON sys_role.id=sys_user_role.roleId " +
            "where sys_user_role.userId=#{userId}")
    List<SysRole> findRoleAllByUserId(@Param("userId") int userId);


    @Delete("delete from sys_user_role where sys_user_role.userId=#{userId}")
    int deleteByUserId(@Param("userId")int userId);
}